package cn.rocky.prepare;

public class myPow {

    public static double myPow(double x, int n) {
        long N = n;
        return N >= 0 ? quickMul(x, N) : 1.0 / quickMul(x, -N);
    }

    private static double quickMul(double x, long l) {
        if (l == 0) { return 1.0;}
        double y = quickMul(x, l / 2);
        return l % 2 == 0 ? y * y : y * y * x;
    }

    public static void main(String[] args) {
        System.out.println(myPow(2.000, 10));
        System.out.println(myPow(2.100, 3));
        System.out.println(myPow(2.000, -2));
    }
}
